#ifndef PHYSICS_H
#define PHYSICS_H

#include "gameworld.h"
#include <stack>
#include <vector>
using namespace::std;

#define GRAVITY 0.0006f
#define NAN -112112;

struct Collision{
	float start;
	Entity* ent1;
	Entity* ent2;
};

class Physics
{
public:
	static const short LEFT = 0;
	static const short RIGHT = 1;
	static const short TOP = 2;
	static const short BOTTOM = 3;
	static const short FRONT = 4;
	static const short BACK = 5;

	Physics(void);
	~Physics(void);

	static float sqDistPointToBox(float sx,float sy, float sz, float cx, float cy, float cz, float w, float h, float d);

	stack<Collision*>* collisions;
	Collision* frameCollisions[300];
	vector<Entity*>* entitiesToRemove;
	
	int getEntityCollisions(GameWorld* game, int numEntities, int numCols);
	int removeCollisionsWithEntity(int numCols, Entity* entity);
	int getNewEntityCollisions(GameWorld* game, int numCols, Entity* c, float currentPercent);
	void fixCollision(GameWorld* game, Collision* c);
	void update(GameWorld* game);
	void sort(int first, int last);
	int partition(int top, int bottom);
	bool willCollideWithTile(int x, int y);
	void sort(int num);
	void moveEntitiesByPercent(GameWorld* game, float percent);
	short getEntityCollisionDirection(Collision* coll);
	void swapEntities(Collision* coll);
	short swapDirections(short dir);
	bool isSorted(Collision** cols);
};

#endif
